<?php

/**
 * Empresa filter form base class.
 *
 * @package    cronos-doctrine
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseEmpresaFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'padre'       => new sfWidgetFormFilterInput(),
      'entidad_id'  => new sfWidgetFormFilterInput(),
      'nombre'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'rif'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'logo'        => new sfWidgetFormFilterInput(),
      'correo'      => new sfWidgetFormFilterInput(),
      'correo_inf'  => new sfWidgetFormFilterInput(),
      'expires_at'  => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'iva'         => new sfWidgetFormFilterInput(),
      'feriados'    => new sfWidgetFormChoice(array('choices' => array('' => '', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7'))),
      'created_at'  => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'  => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'idioma_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Idioma')),
      'moneda_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Moneda')),
      'pago_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Pago')),
    ));

    $this->setValidators(array(
      'padre'       => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'entidad_id'  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'nombre'      => new sfValidatorPass(array('required' => false)),
      'rif'         => new sfValidatorPass(array('required' => false)),
      'logo'        => new sfValidatorPass(array('required' => false)),
      'correo'      => new sfValidatorPass(array('required' => false)),
      'correo_inf'  => new sfValidatorPass(array('required' => false)),
      'expires_at'  => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'iva'         => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'feriados'    => new sfValidatorChoice(array('required' => false, 'choices' => array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7'))),
      'created_at'  => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'  => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'idioma_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Idioma', 'required' => false)),
      'moneda_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Moneda', 'required' => false)),
      'pago_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Pago', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('empresa_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addIdiomaListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.EmpresaHasIdioma EmpresaHasIdioma')
      ->andWhereIn('EmpresaHasIdioma.idioma_id', $values)
    ;
  }

  public function addMonedaListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.EmpresaHasMoneda EmpresaHasMoneda')
      ->andWhereIn('EmpresaHasMoneda.moneda_id', $values)
    ;
  }

  public function addPagoListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.EmpresaHasPago EmpresaHasPago')
      ->andWhereIn('EmpresaHasPago.pago_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Empresa';
  }

  public function getFields()
  {
    return array(
      'id'          => 'Number',
      'padre'       => 'Number',
      'entidad_id'  => 'Number',
      'nombre'      => 'Text',
      'rif'         => 'Text',
      'logo'        => 'Text',
      'correo'      => 'Text',
      'correo_inf'  => 'Text',
      'expires_at'  => 'Date',
      'iva'         => 'Number',
      'feriados'    => 'Enum',
      'created_at'  => 'Date',
      'updated_at'  => 'Date',
      'idioma_list' => 'ManyKey',
      'moneda_list' => 'ManyKey',
      'pago_list'   => 'ManyKey',
    );
  }
}
